package com.example.demo.controller;

import com.example.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

// AccountController.java
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @GetMapping("/demo-rr")
    public String demoRR(@RequestParam Long userId) {
        accountService.demonstrateRepeatableRead(userId);
        return "可重复读演示完成";
    }

    @GetMapping("/demo-rc")
    public String demoRC(@RequestParam Long userId) {
        accountService.demonstrateReadCommitted(userId);
        return "读已提交演示完成";
    }

    @PostMapping("/transfer")
    public String transfer(@RequestParam Long from, @RequestParam Long to, @RequestParam BigDecimal amount) {
        accountService.transferMoney(from, to, amount);
        return "转账成功";
    }
}